namespace CSharpPro;

public class Demo1
{
    public static void TestPrint1()
    {
        Console.WriteLine("请输入x,y,z：");
        int x = Convert.ToInt32(Console.ReadLine());
        int y = Convert.ToInt32(Console.ReadLine());
        int z = Convert.ToInt32(Console.ReadLine());

        int[] numbers = { x, y, z };
        Array.Sort(numbers);

        Console.WriteLine("从小到大排序后的结果为：{0}, {1}, {2}", numbers[0], numbers[1], numbers[2]);
    }


    public static void TestPrint2()
    {
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 == 0 || i.ToString().Contains("7"))
            {
                continue;
            }
            Console.Write(i + " ");
            sum += i;
        }
        Console.WriteLine("\n1 - 100 之间所有不是 7 的倍数和不包含 7 的数字的和为：" + +sum);
    }

    public static void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }
            Console.WriteLine();
        }
    }


    public static void TestPrint4()
    {
        List<int> perfectNumbers = new List<int>();
        for (int i = 2; i < 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }
            if (sum == i)
            {
                perfectNumbers.Add(i);
            }
        }
        Console.WriteLine("1000 以内的完数有：");
        foreach (int num in perfectNumbers)
        {
            Console.Write(num + " ");
        }
    }


    public static void TestPrint5()
    {
        Console.WriteLine("请输入一个正整数：");
        string input = Console.ReadLine();
        int num = int.Parse(input);
        
        int digitCount = input.Length;
        Console.WriteLine($"{num} 是 {digitCount} 位数");
        
        Console.Write("逆序的各位数字为：");
        for (int i = input.Length - 1; i >= 0; i--)
        {
            Console.Write(input[i] + " ");
        }
        Console.WriteLine();
    }


    public static void TestPrint6()
    {
        Console.WriteLine("请输入菱形的行数（应为奇数）：");
        int n = Convert.ToInt32(Console.ReadLine());
        
        for (int i = 1; i <= n / 2 + 1; i++)
        {
            for (int j = 1; j <= n / 2 + 1 - i; j++)
            {
                Console.Write(" ");
            }
            for (int k = 1; k <= 2 * i - 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
        
        for (int i = n / 2; i >= 1; i--)
        {
            for (int j = 1; j <= n / 2 + 1 - i; j++)
            {
                Console.Write(" ");
            }
            for (int k = 1; k <= 2 * i - 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}